/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller.actions;

import controler.formbeans.AdminBean;
import java.io.File;
import java.io.FileOutputStream;
import java.util.Date;
import java.util.Iterator;
import java.util.Vector;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.logic.db.AdminFunctionality;
import model.logic.db.CommonWSFunctionality;
import model.logic.db.UserFunctions;
import model.pojo.AboutUs;
import model.pojo.Admins;
import model.pojo.ApplicantCompanies;
import model.pojo.Applicants;
import model.pojo.CareerCategories;
import model.pojo.ContactUsMsg;
import model.pojo.Countries;
import model.pojo.EducationLevels;
import model.pojo.Grades;
import model.pojo.Industries;
import model.pojo.Institutes;
import model.pojo.News;
import model.pojo.NewsCategories;
import model.pojo.Products;
import model.pojo.Services;
import model.pojo.Settings;
import model.pojo.StudyFields;
import model.pojo.Uploads;
import model.pojo.Users;
import model.pojo.Vacancies;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.upload.FormFile;

/**
 *
 * @author maha
 */
public class AdminAction extends DispatchAction {
    
    public ActionForward Inbox(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminFunctionality af = new AdminFunctionality();
        Vector<ContactUsMsg> membersMsgs = af.getMembersMsgs();
        ((AdminBean) form).setContactUsMsg(membersMsgs);
        return mapping.findForward("inbox");
    }
    
    public ActionForward deleteMsg(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("inbox"));
        AdminFunctionality af = new AdminFunctionality();
        int deleteMsg = af.deleteMsg(((AdminBean) form).getMgId());
        if (deleteMsg != 0) {
            Vector<ContactUsMsg> membersMsgs = af.getMembersMsgs();
            ((AdminBean) form).setContactUsMsg(membersMsgs);
            return redirect;
        } else {
            ((AdminBean) form).setInfoMsg("Can't Delete Msg, Try again Later!!");
            forward = mapping.findForward("fail");
        }
        return forward;
    }
    //====================Vacancies Action "Edit/Update/Delete"==============

    public ActionForward VacancyInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminFunctionality af = new AdminFunctionality();
        ((AdminBean) form).setVac(af.getAllVacancies());
        return mapping.findForward("vacinfo");
    }
    
    public ActionForward addVacancy(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        AdminBean bean = ((AdminBean) form);
        Vacancies vac = new Vacancies();
        vac.setVacancyTitle(bean.getVacancyTitle());
        vac.setPositionType(bean.getPositionType());
        vac.setAvailableVacancyNumber(bean.getAvailableVacancyNumber());
        vac.setDeadline(bean.getDeadline());
        vac.setRefrence(bean.getRefrence());
        vac.setDescription(bean.getDescription());
        vac.setShowVacancy(bean.getShowVacancy());
        AdminFunctionality ad = new AdminFunctionality();
        int addVacancy = ad.addVacancy(vac);
        if (addVacancy != 0) {
            
            ((AdminBean) form).setVac(ad.getAllVacancies());
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("vacinfo"));
            return redirect;
            // forward = mapping.findForward("vacinfo");
        } else {
            ((AdminBean) form).setVac(ad.getAllVacancies());
            forward = mapping.findForward("notify");
        }
        return forward;
    }
    
    public ActionForward VacancyUpdate(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        AdminBean bean = (AdminBean) form;
        Vacancies vac = new Vacancies();
        vac.setVacancyId(bean.getVacancyId());
        vac.setVacancyTitle(bean.getVacancyTitle());
        vac.setAvailableVacancyNumber(bean.getAvailableVacancyNumber());
        vac.setPositionType(bean.getPositionType());
        vac.setDeadline(bean.getDeadline());
        vac.setRefrence(bean.getRefrence());
        vac.setShowVacancy(bean.getShowVacancy());
        vac.setDescription(bean.getDescription());
        AdminFunctionality af = new AdminFunctionality();
        int updateVacancy = af.updateVacancy(vac);
        if (updateVacancy != 0) {
            ((AdminBean) form).setVac(af.getAllVacancies());
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("vacinfo"));
            return redirect;
            //  forward = mapping.findForward("vacinfo");
        } else {
            ((AdminBean) form).setVac(af.getAllVacancies());
            forward = mapping.findForward("notify");
        }
        
        
        return forward;
    }
    
    public ActionForward VacancyDelete(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        AdminFunctionality af = new AdminFunctionality();
        System.out.println(((AdminBean) form).getVacancyId());
        int deleteVacancy = af.deleteVacancy(((AdminBean) form).getVacancyId());
        System.out.println(deleteVacancy);
        
        if (deleteVacancy != 0) {
            ((AdminBean) form).setVac(af.getAllVacancies());
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("vacinfo"));
            return redirect;
            // forward = mapping.findForward("vacinfo");
        } else {
            ((AdminBean) form).setVac(af.getAllVacancies());
            forward = mapping.findForward("notify");
        }
        return forward;
    }
    //========================Country Methods=============================

    public ActionForward CountryInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setCountries(uf.getCountries());
        return mapping.findForward("countryinfo");
    }
    
    public ActionForward addCountry(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        Countries country = new Countries();
        country.setCountryName(((AdminBean) form).getCountryName());
        AdminFunctionality a = new AdminFunctionality();
        int addCountry = a.addCountry(country);
        
        UserFunctions uf = new UserFunctions();
        if (addCountry != 0) {
            
            ((AdminBean) form).setCountries(uf.getCountries());
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("countryinfo"));
            return redirect;
            //forward = mapping.findForward("countryinfo");
        } else {
            forward = mapping.findForward("notify");
        }
        return forward;
    }
    
    public ActionForward updateCountry(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        AdminBean bean = (AdminBean) form;
        Countries c = new Countries();
        c.setCountryId(bean.getCountryId());
        c.setCountryName(bean.getCountryName());
        AdminFunctionality af = new AdminFunctionality();
        int updateCountry = af.updateCountry(c);
        
        UserFunctions uf = new UserFunctions();
        if (updateCountry != 0) {
            ((AdminBean) form).setCountries(uf.getCountries());
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("countryinfo"));
            return redirect;
            // forward = mapping.findForward("countryinfo");
        } else {
            forward = mapping.findForward("notify");
        }
        
        return forward;
    }
    
    public ActionForward deleteCountry(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        AdminBean bean = (AdminBean) form;
        AdminFunctionality af = new AdminFunctionality();
        int deleteCountry = af.deleteCountry(bean.getCountryId());
        
        UserFunctions uf = new UserFunctions();
        if (deleteCountry != 0) {
            ((AdminBean) form).setCountries(uf.getCountries());
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("countryinfo"));
            return redirect;
            //forward = mapping.findForward("countryinfo");
        } else {
            forward = mapping.findForward("notify");
        }
        
        return forward;
    }
    //=====================================================================

    //==========================Grades=================================
    public ActionForward GradeInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        return mapping.findForward("GradeInfo");
    }
    
    public ActionForward addGrade(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String gname = ((AdminBean) form).getGradeName();
        Grades g = new Grades();
        g.setGradeName(gname);
        AdminFunctionality af = new AdminFunctionality();
        af.addGrade(g);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("GradeInfo"));
        return redirect;
        //  return mapping.findForward("GradeInfo");
    }
    
    public ActionForward deleteGrade(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int gId = ((AdminBean) form).getGradeId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteGrade(gId);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("GradeInfo"));
        return redirect;
        // return mapping.findForward("GradeInfo");
    }
    
    public ActionForward updateGrade(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        Grades g = new Grades();
        g.setGradeId(bean.getGradeId());
        g.setGradeName(bean.getGradeName());
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateGrade(g);
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("GradeInfo"));
        return redirect;
        //  return mapping.findForward("GradeInfo");
    }
    //=====================Institues=====================================

    public ActionForward InstituteInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInstitutes(uf.getInst());
        return mapping.findForward("InstituteInfo");
    }
    
    public ActionForward addInstitues(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String gname = ((AdminBean) form).getInstituteName();
        Institutes inst = new Institutes();
        
        inst.setInstituteName(gname);
        AdminFunctionality af = new AdminFunctionality();
        af.addInstitute(inst);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInstitutes(uf.getInst());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("InstituteInfo"));
        return redirect;
        // return mapping.findForward("InstituteInfo");
    }
    
    public ActionForward deleteInstitute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int gId = ((AdminBean) form).getInstituteId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteInstitute(gId);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInstitutes(uf.getInst());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("InstituteInfo"));
        return redirect;
        // return mapping.findForward("InstituteInfo");
    }
    
    public ActionForward updateInstitue(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        Institutes g = new Institutes();
        g.setInstituteId(bean.getInstituteId());
        g.setInstituteName(bean.getInstituteName());
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateInstitute(g);
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInstitutes(uf.getInst());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("InstituteInfo"));
        return redirect;
        //return mapping.findForward("InstituteInfo");
    }
    //==============================levels===========================

    public ActionForward LevelInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setLevels(uf.getEduLevels());
        return mapping.findForward("LevelInfo");
    }
    
    public ActionForward addLevel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String gname = ((AdminBean) form).getEducationLevelName();
        EducationLevels inst = new EducationLevels();
        
        inst.setEducationLevelName(gname);
        AdminFunctionality af = new AdminFunctionality();
        af.addLevel(inst);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setLevels(uf.getEduLevels());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("LevelInfo"));
        return redirect;
        // return mapping.findForward("LevelInfo");
    }
    
    public ActionForward deleteLevel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int gId = ((AdminBean) form).getEducationLevelId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteLevel(gId);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setLevels(uf.getEduLevels());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("LevelInfo"));
        return redirect;
        // return mapping.findForward("LevelInfo");
    }
    
    public ActionForward updateLevel(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        EducationLevels g = new EducationLevels();
        g.setEducationLevelId(bean.getEducationLevelId());
        g.setEducationLevelName(bean.getEducationLevelName());
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateLevel(g);
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setLevels(uf.getEduLevels());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("LevelInfo"));
        return redirect;
        // return mapping.findForward("LevelInfo");
    }
    //=======================Study Fields===================================

    public ActionForward StudyFieldInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setStudy(uf.getStudyFields());
        return mapping.findForward("StudyFieldInfo");
    }
    
    public ActionForward addStudyField(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String gname = ((AdminBean) form).getStudyFieldName();
        StudyFields inst = new StudyFields();
        
        inst.setStudyFieldName(gname);
        AdminFunctionality af = new AdminFunctionality();
        af.addStudyField(inst);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setStudy(uf.getStudyFields());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("StudyFieldInfo"));
        return redirect;
        //return mapping.findForward("StudyFieldInfo");
    }
    
    public ActionForward deleteStudyField(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int gId = ((AdminBean) form).getStudyFieldId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteStudyField(gId);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setStudy(uf.getStudyFields());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("StudyFieldInfo"));
        return redirect;
        // return mapping.findForward("StudyFieldInfo");
    }
    
    public ActionForward updateStudyField(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        StudyFields g = new StudyFields();
        g.setStudyFieldId(bean.getStudyFieldId());
        g.setStudyFieldName(bean.getStudyFieldName());
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateStudyField(g);
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setStudy(uf.getStudyFields());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("StudyFieldInfo"));
        return redirect;
        //  return mapping.findForward("StudyFieldInfo");
    }

    //================industries==================================
    public ActionForward IndustryInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInd(uf.getIndustries());
        return mapping.findForward("IndustryInfo");
    }
    
    public ActionForward addIndustry(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String gname = ((AdminBean) form).getIndustryTitle();
        Industries inst = new Industries();
        
        inst.setIndustryTitle(gname);
        AdminFunctionality af = new AdminFunctionality();
        af.addIndustry(inst);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInd(uf.getIndustries());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("IndustryInfo"));
        return redirect;
        // return mapping.findForward("IndustryInfo");
    }
    
    public ActionForward deleteIndustry(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int gId = ((AdminBean) form).getIndustryId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteIndustry(gId);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInd(uf.getIndustries());
        return mapping.findForward("IndustryInfo");
    }
    
    public ActionForward updateIndustry(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        Industries g = new Industries();
        g.setIndustryId(bean.getIndustryId());
        g.setIndustryTitle(bean.getIndustryTitle());
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateIndustries(g);
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setInd(uf.getIndustries());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("IndustryInfo"));
        return redirect;
        // return mapping.findForward("IndustryInfo");
    }

//==================ccat========================================
    public ActionForward CareerCategoryInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setCat(uf.getCareers());
        return mapping.findForward("CareerCategoryInfo");
    }
    
    public ActionForward addCareerCat(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String gname = ((AdminBean) form).getCareerCategoryTitle();
        CareerCategories inst = new CareerCategories();
        
        inst.setCareerCategoryTitle(gname);
        AdminFunctionality af = new AdminFunctionality();
        af.addCareerCategory(inst);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setCat(uf.getCareers());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("CareerCategoryInfo"));
        return redirect;
        // return mapping.findForward("CareerCategoryInfo");
    }
    
    public ActionForward deleteCareerCat(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int gId = ((AdminBean) form).getCareerCategoryId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteCareerCategory(gId);
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setCat(uf.getCareers());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("CareerCategoryInfo"));
        return redirect;
        // return mapping.findForward("CareerCategoryInfo");
    }
    
    public ActionForward updateCareerCat(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        CareerCategories g = new CareerCategories();
        g.setCareerCategoryId(bean.getCareerCategoryId());
        g.setCareerCategoryTitle(bean.getCareerCategoryTitle());
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateCareerCategory(g);
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setCat(uf.getCareers());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("CareerCategoryInfo"));
        return redirect;
        //  return mapping.findForward("CareerCategoryInfo");
    }

    //================NewsCategoryInfo=============
    public ActionForward NewsCategoryInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        CommonWSFunctionality c = new CommonWSFunctionality();
        ((AdminBean) form).setNcat(c.getCat());
        return mapping.findForward("NewsCategoryInfo");
    }
    
    public ActionForward addNewsCategory(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        String ncname = ((AdminBean) form).getNewsCategoryTitle();
        String nccomments = ((AdminBean) form).getComments();
        String nduedate = ((AdminBean) form).getDueDate();
        String ncperiod = ((AdminBean) form).getPeriod();
        NewsCategories inst = new NewsCategories();
        inst.setNewsCategoryTitle(ncname);
        inst.setComments(nccomments);
        inst.setDueDate(nduedate);
        inst.setPeriod(ncperiod);
        
        AdminFunctionality af = new AdminFunctionality();
        af.addNewsCategory(inst);
        CommonWSFunctionality c = new CommonWSFunctionality();
        ((AdminBean) form).setNcat(c.getCat());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("NewsCategoryInfo"));
        return redirect;
        //return mapping.findForward("NewsCategoryInfo");
    }
    
    public ActionForward deleteNewsCategory(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int gId = ((AdminBean) form).getNewsCategoryId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteNewsCategory(gId);
        CommonWSFunctionality c = new CommonWSFunctionality();
        ((AdminBean) form).setNcat(c.getCat());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("NewsCategoryInfo"));
        return redirect;
        //return mapping.findForward("NewsCategoryInfo");
    }
    
    public ActionForward updateNewsCategory(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        NewsCategories g = new NewsCategories();
        g.setNewsCategoryId(bean.getNewsCategoryId());
        g.setNewsCategoryTitle(bean.getNewsCategoryTitle());
        g.setComments(bean.getComments());
        g.setPeriod(bean.getPeriod());
        g.setDueDate(bean.getDueDate());
        AdminFunctionality af = new AdminFunctionality();
        af.updateNewsCategory(g);
        
        CommonWSFunctionality c = new CommonWSFunctionality();
        ((AdminBean) form).setNcat(c.getCat());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("NewsCategoryInfo"));
        return redirect;
        // return mapping.findForward("NewsCategoryInfo");
    }
    //================admin work================================

    public ActionForward PromotAdmin(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminFunctionality admin = new AdminFunctionality();
        ((AdminBean) form).setAdmins(admin.getAdmins());
        ((AdminBean) form).setPrivi(admin.getPrivilidges());
        return mapping.findForward("PromotAdmin");
    }
    
    public ActionForward deleteAdmin(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminFunctionality admin = new AdminFunctionality();
        admin.deleteAdmin(((AdminBean) form).getAdminId());
        ((AdminBean) form).setAdmins(admin.getAdmins());
        ((AdminBean) form).setPrivi(admin.getPrivilidges());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("PromotAdmin"));
        return redirect;
        //return mapping.findForward("PromotAdmin");
    }
    
    public ActionForward deletePriv(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int adminid = ((AdminBean) form).getAdminId();
        int privid = ((AdminBean) form).getPrivilegeId();
        
        AdminFunctionality admin = new AdminFunctionality();
        admin.removePriviled(adminid, privid);
        ((AdminBean) form).setPrivilegeName("");
        ((AdminBean) form).setAdmins(admin.getAdmins());
        ((AdminBean) form).setPrivi(admin.getPrivilidges());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("PromotAdmin"));
        return redirect;
        // return mapping.findForward("PromotAdmin");
    }
    
    public ActionForward addPriv(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        ActionForward forward = new ActionForward();
        int adminid = ((AdminBean) form).getAdminId();
        int privid = ((AdminBean) form).getPrivilegeId();
        
        AdminFunctionality admin = new AdminFunctionality();
        int addPriviled = admin.addPriviled(adminid, privid);
        ((AdminBean) form).setPrivilegeName("");
        ((AdminBean) form).setAdmins(admin.getAdmins());
        ((AdminBean) form).setPrivi(admin.getPrivilidges());
        if (addPriviled == 0) {
            forward = mapping.findForward("admindone");
        } else {
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("PromotAdmin"));
            return redirect;
            // forward = mapping.findForward("PromotAdmin");
        }
        return forward;
    }
    
    public ActionForward addAdmin(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        Admins admin = new Admins();
        admin.setAdminName(((AdminBean) form).getAdminName());
        admin.setAdminEmail(((AdminBean) form).getAdminEmail());
        admin.setAdminPassword(((AdminBean) form).getAdminPassword());
        admin.setCreatedBy(((AdminBean) form).getCreatedBy());
        AdminFunctionality adminf = new AdminFunctionality();
        adminf.addAdmin(admin);
        ((AdminBean) form).setPrivilegeName("");
        ((AdminBean) form).setAdmins(adminf.getAdmins());
        ((AdminBean) form).setPrivi(adminf.getPrivilidges());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("PromotAdmin"));
        return redirect;
        // return mapping.findForward("PromotAdmin");
    }
    //===================Services==========================

    public ActionForward ServiceInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        CommonWSFunctionality wf = new CommonWSFunctionality();
        ((AdminBean) form).setService(wf.getServicesAndContents());
        return mapping.findForward("ServiceInfo");
    }
    
    public ActionForward goToUpdateService(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean b = (AdminBean) form;
        Integer serviceId = b.getServiceId();
        AdminFunctionality af = new AdminFunctionality();
        ((AdminBean) form).setServices(af.getService(serviceId));
        
        
        return mapping.findForward("us");
    }
    
    public ActionForward updateService(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = ((AdminBean) form);
        Services serv = new Services();
        serv.setServiceId(bean.getServiceId());
        serv.setServiceName(bean.getServiceName());
        serv.setServiceDescription(bean.getServiceDescription());
        serv.setServiceShortDescription(bean.getServiceShortDescription());
        serv.setShowMenu(bean.getShowMenu());
        //upload logo

        
        
        
        String path = "../../web/styles/upload/ServicesImages";
        ServletContext servletContext = request.getServletContext();
        String filePath = servletContext.getRealPath(path);
        
        FormFile serviceLog = bean.getServiceLog();
        
        if (serviceLog.getFileName().equals("") || serviceLog.getFileName() == null) {
            String hiddenServiceLogo = bean.getHiddenServiceLogo();
            serv.setServiceLogo(hiddenServiceLogo);
        } else {
            
            
            System.out.println(filePath);
            
            File folder = new File(filePath);
            if (!folder.exists()) {
                boolean mkdir = folder.mkdir();
                
            }
            
            String fileName = serviceLog.getFileName();
            
            if (!("").equals(fileName)) {
                
                File newFile = new File(filePath, fileName);
                
                
                
                serv.setServiceLogo("styles/upload/ServicesImages" + "/" + fileName);
                
                
                if (!newFile.exists()) {
                    FileOutputStream fos = new FileOutputStream(newFile);
                    fos.write(serviceLog.getFileData());
                    fos.flush();
                    fos.close();
                    System.out.println("Uploaded");
                }
                
                
            }
            
        }
        
        
        FormFile serviceImg = bean.getServiceImg();
        
        if (serviceImg.getFileName().equals("") || serviceImg.getFileName() == null) {
            String hiddenServiceImg = bean.getHiddenServiceImage();
            serv.setServiceImage(hiddenServiceImg);
        } else {
            String fileName2 = serviceImg.getFileName();
            
            if (!("").equals(fileName2)) {
                
                File newFile = new File(filePath, fileName2);
                serv.setServiceImage("styles/upload/ServicesImages" + "/" + fileName2);
                
                
                if (!newFile.exists()) {
                    FileOutputStream fos = new FileOutputStream(newFile);
                    fos.write(serviceLog.getFileData());
                    fos.flush();
                    fos.close();
                    System.out.println("Uploaded");
                }
                
                
            }
        }
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateService(serv);
        
        
        CommonWSFunctionality wf = new CommonWSFunctionality();
        ((AdminBean) form).setService(wf.getServicesAndContents());;
        return mapping.findForward("ServiceInfo");
    }
    
    public ActionForward addService(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = ((AdminBean) form);
        Services serv = new Services();
        serv.setServiceName(bean.getServiceName());
        serv.setServiceDescription(bean.getServiceDescription());
        serv.setServiceShortDescription(bean.getServiceShortDescription());
        serv.setShowMenu(bean.getShowMenu());



        //upload logo

        FormFile serviceLog = bean.getServiceLog();
        
        
        ServletContext servletContext = request.getServletContext();
        String path = "../../web/styles/upload/ServicesImages";
        
        String filePath = servletContext.getRealPath(path);
        
        System.out.println(filePath);
        
        File folder = new File(filePath);
        if (!folder.exists()) {
            boolean mkdir = folder.mkdir();
            
        }
        
        String fileName = serviceLog.getFileName();
        
        if (!("").equals(fileName)) {
            
            File newFile = new File(filePath, fileName);
            
            
            
            serv.setServiceLogo("styles/upload/ServicesImages" + "/" + fileName);
            
            
            if (!newFile.exists()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                fos.write(serviceLog.getFileData());
                fos.flush();
                fos.close();
                System.out.println("Uploaded");
            }
            
            
        }
        
        
        FormFile serviceImg = bean.getServiceImg();
        
        
        
        String fileName2 = serviceImg.getFileName();
        
        if (!("").equals(fileName2)) {
            
            File newFile = new File(filePath, fileName2);
            serv.setServiceImage("styles/upload/ServicesImages" + "/" + fileName2);
            
            
            if (!newFile.exists()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                fos.write(serviceLog.getFileData());
                fos.flush();
                fos.close();
                System.out.println("Uploaded");
            }
            
            
        }
        
        AdminFunctionality af = new AdminFunctionality();
        af.addService(serv);
        
        CommonWSFunctionality wf = new CommonWSFunctionality();
        ((AdminBean) form).setService(wf.getServicesAndContents());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("ServiceInfo"));
        return redirect;
        // return mapping.findForward("ServiceInfo");
    }
    
    public ActionForward deleteService(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int id = ((AdminBean) form).getServiceId();
        AdminFunctionality af = new AdminFunctionality();
        af.deleteService(id);
        CommonWSFunctionality wf = new CommonWSFunctionality();
        ((AdminBean) form).setService(wf.getServicesAndContents());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("ServiceInfo"));
        return redirect;
        // return mapping.findForward("ServiceInfo");
    }
    //=========================news=================

    public ActionForward NewsInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setNewsCategory(cf.getCat());
        ((AdminBean) form).setNews(cf.getNews());
        return mapping.findForward("NewsInfo");
    }
    
    public ActionForward updateNews(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setNewsCategory(cf.getCat());
        ((AdminBean) form).setNews(cf.getnews(((AdminBean) form).getNewsId()));
        return mapping.findForward("unews");
    }
    
    public ActionForward UpdateNews(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        System.out.println("Here");
        
        AdminBean bean = ((AdminBean) form);
        News news = new News();
        news.setNewsTitle(bean.getNewsTitle());
        news.setNewsShortDescription(bean.getNewsShortDescription());
        news.setNewsDescription(bean.getNewsDescription());
        news.setShowHome(bean.getShowHome());
        NewsCategories n = new NewsCategories();
        n.setNewsCategoryId(bean.getNewsCategoryId());
        news.setNewsCategories(n);
        news.setNewsId(bean.getNewsId());
        
        String newshiddenLog = bean.getHiddenNewsLogo();
        String newshiddenImg = bean.getHiddenNewsImage();

        //================upload logo============
        FormFile newsLog = bean.getNewsLog();
        
        
        
        ServletContext servletContext = request.getServletContext();
        String path = "../../web/styles/upload/NewsImages";
        
        String filePath = servletContext.getRealPath(path);
        
        if (newsLog.getFileName().equals("") || newsLog.getFileName() == null) {
            news.setNewsLogo(newshiddenLog);
        } else {
            File folder = new File(filePath);
            if (!folder.exists()) {
                boolean mkdir = folder.mkdir();
                
            }
            
            String fileName = newsLog.getFileName();
            System.out.println(fileName);
            if (!("").equals(fileName)) {
                
                File newFile = new File(filePath, fileName);
                
                
                
                news.setNewsLogo("styles/upload/NewsImages" + "/" + fileName);
                
                
                if (!newFile.exists()) {
                    FileOutputStream fos = new FileOutputStream(newFile);
                    fos.write(newsLog.getFileData());
                    fos.flush();
                    fos.close();
                    System.out.println("Uploaded");
                }
                
                
            }
        }
        //=======================================

        FormFile newsImg = bean.getNewsImg();
        if (newsImg.getFileName().equals("") || newsImg.getFileName() == null) {
            news.setNewsImage(newshiddenImg);
        } else {
            File folder2 = new File(filePath);
            if (!folder2.exists()) {
                boolean mkdir = folder2.mkdir();
                
            }
            
            String fileName2 = newsImg.getFileName();
            
            if (!("").equals(fileName2)) {
                
                File newFile = new File(filePath, fileName2);
                
                
                
                news.setNewsImage("styles/upload/NewsImages" + "/" + fileName2);
                
                
                if (!newFile.exists()) {
                    FileOutputStream fos = new FileOutputStream(newFile);
                    fos.write(newsImg.getFileData());
                    fos.flush();
                    fos.close();
                    System.out.println("Uploaded");
                }
                
                
            }
        }
        news.setCreationDate(new Date().toString());
        AdminFunctionality ad = new AdminFunctionality();
        ad.updateNews(news);
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setNewsCategory(cf.getCat());
        ((AdminBean) form).setNews(cf.getNews());
        return mapping.findForward("NewsInfo");
    }
    
    public ActionForward deleteNews(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminFunctionality admin = new AdminFunctionality();
        admin.deleteNews(((AdminBean) form).getNewsId());
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setNews(cf.getNews());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("NewsInfo"));
        return redirect;
        //return mapping.findForward("NewsInfo");
    }
    
    public ActionForward addNews(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = ((AdminBean) form);
        News news = new News();
        news.setNewsTitle(bean.getNewsTitle());
        news.setNewsShortDescription(bean.getNewsShortDescription());
        news.setNewsDescription(bean.getNewsDescription());
        news.setShowHome(bean.getShowHome());
        NewsCategories n = new NewsCategories();
        n.setNewsCategoryId(bean.getNewsCategoryId());
        news.setNewsCategories(n);



        //================upload logo============
        FormFile newsLog = bean.getNewsLog();
        
        System.out.println(newsLog.getFileName());
        
        ServletContext servletContext = request.getServletContext();
        String path = "../../web/styles/upload/NewsImages";
        
        String filePath = servletContext.getRealPath(path);
        
        
        
        File folder = new File(filePath);
        if (!folder.exists()) {
            boolean mkdir = folder.mkdir();
            
        }
        
        String fileName = newsLog.getFileName();
        
        if (!("").equals(fileName)) {
            
            File newFile = new File(filePath, fileName);
            
            
            
            news.setNewsLogo("styles/upload/NewsImages" + "/" + fileName);
            
            
            if (!newFile.exists()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                fos.write(newsLog.getFileData());
                fos.flush();
                fos.close();
                System.out.println("Uploaded");
            }
            
            
        }

        //=======================================

        FormFile newsImg = bean.getNewsImg();
        File folder2 = new File(filePath);
        if (!folder2.exists()) {
            boolean mkdir = folder2.mkdir();
            
        }
        
        String fileName2 = newsImg.getFileName();
        
        if (!("").equals(fileName)) {
            
            File newFile = new File(filePath, fileName2);
            
            
            
            news.setNewsImage("styles/upload/NewsImages" + "/" + fileName);
            
            
            if (!newFile.exists()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                fos.write(newsImg.getFileData());
                fos.flush();
                fos.close();
                System.out.println("Uploaded");
            }
            
            
        }
        
        news.setCreationDate(new Date().toString());
        AdminFunctionality ad = new AdminFunctionality();
        ad.addNews(news);
        
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setNews(cf.getNews());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("NewsInfo"));
        return redirect;
        //return mapping.findForward("NewsInfo");
    }
//===========================Products=========================

    public ActionForward ProductInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setProducts(cf.getProductsAndContents());
        return mapping.findForward("ProductInfo");
    }
    
    public ActionForward redirectToUpdateProduct(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        Integer productId = bean.getProductId();
        AdminFunctionality af = new AdminFunctionality();
        ((AdminBean) form).setProducts(af.getProduct(productId));
        
        return mapping.findForward("up");
    }
    
    public ActionForward updateProducts(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = ((AdminBean) form);
        Products serv = new Products();
        serv.setProductId(bean.getProductId());
        serv.setProductName(bean.getProductName());
        serv.setProductDescription(bean.getProductDescription());
        serv.setProductShortDescription(bean.getProductShortDescription());
        serv.setShowMenu(bean.getShowMenu());
        //upload logo

        
        
        
        String path = "../../web/styles/upload/ProductsImages";
        ServletContext servletContext = request.getServletContext();
        String filePath = servletContext.getRealPath(path);
        
        FormFile serviceLog = bean.getProductLog();
        
        if (serviceLog.getFileName().equals("") || serviceLog.getFileName() == null) {
            String hiddenServiceLogo = bean.getHiddenProductLogo();
            serv.setProductLogo(hiddenServiceLogo);
        } else {
            
            
            System.out.println(filePath);
            
            File folder = new File(filePath);
            if (!folder.exists()) {
                boolean mkdir = folder.mkdir();
                
            }
            
            String fileName = serviceLog.getFileName();
            
            if (!("").equals(fileName)) {
                
                File newFile = new File(filePath, fileName);
                
                
                
                serv.setProductLogo("styles/upload/ProductsImages" + "/" + fileName);
                
                
                if (!newFile.exists()) {
                    FileOutputStream fos = new FileOutputStream(newFile);
                    fos.write(serviceLog.getFileData());
                    fos.flush();
                    fos.close();
                    System.out.println("Uploaded");
                }
                
                
            }
            
        }
        
        
        FormFile serviceImg = bean.getProductImg();
        
        if (serviceImg.getFileName().equals("") || serviceImg.getFileName() == null) {
            String hiddenServiceImg = bean.getHiddenProductImage();
            serv.setProductImage(hiddenServiceImg);
        } else {
            String fileName2 = serviceImg.getFileName();
            
            if (!("").equals(fileName2)) {
                
                File newFile = new File(filePath, fileName2);
                serv.setProductImage("styles/upload/ProductsImages" + "/" + fileName2);
                
                
                if (!newFile.exists()) {
                    FileOutputStream fos = new FileOutputStream(newFile);
                    fos.write(serviceLog.getFileData());
                    fos.flush();
                    fos.close();
                    System.out.println("Uploaded");
                }
                
                
            }
        }
        
        AdminFunctionality af = new AdminFunctionality();
        af.updateProduct(serv);
        
        
        CommonWSFunctionality wf = new CommonWSFunctionality();
        ((AdminBean) form).setProducts(wf.getProductsAndContents());
        return mapping.findForward("ProductInfo");
    }
    
    public ActionForward deleteProduct(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminFunctionality af = new AdminFunctionality();
        af.deleteProduct(((AdminBean) form).getProductId());
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setProducts(cf.getProductsAndContents());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("ProductInfo"));
        return redirect;
        // return mapping.findForward("ProductInfo");
    }
    
    public ActionForward addProduct(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Products product = new Products();
        AdminBean bean = ((AdminBean) form);
        
        
        product.setProductName(bean.getProductName());
        product.setProductDescription(bean.getProductDescription());
        product.setShowMenu(bean.getShowMenu());
        product.setProductShortDescription(bean.getProductShortDescription());

        //==========upload logo======

        FormFile productLog = bean.getProductLog();
        
        
        
        ServletContext servletContext = request.getServletContext();
        String path = "../../web/styles/upload/ProductsImages";
        
        String filePath = servletContext.getRealPath(path);
        
        
        
        File folder = new File(filePath);
        if (!folder.exists()) {
            boolean mkdir = folder.mkdir();
            
        }
        
        String fileName = productLog.getFileName();
        
        if (!("").equals(fileName)) {
            
            File newFile = new File(filePath, fileName);
            
            
            
            product.setProductLogo("styles/upload/ProductsImages" + "/" + fileName);
            
            
            if (!newFile.exists()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                fos.write(productLog.getFileData());
                fos.flush();
                fos.close();
                System.out.println("Uploaded");
            }
            
            
        }

        //==========upload image===========
        FormFile productImg = bean.getProductImg();
        
        String fileName2 = productImg.getFileName();
        
        if (!("").equals(fileName2)) {
            
            File newFile = new File(filePath, fileName2);
            
            
            
            product.setProductImage("styles/upload/ProductsImages" + "/" + fileName2);
            
            
            if (!newFile.exists()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                fos.write(productImg.getFileData());
                fos.flush();
                fos.close();
                System.out.println("Uploaded");
            }
            
            
        }
        
        
        
        AdminFunctionality af = new AdminFunctionality();
        af.addProduct(product);
        
        CommonWSFunctionality cf = new CommonWSFunctionality();
        ((AdminBean) form).setProducts(cf.getProductsAndContents());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("ProductInfo"));
        return redirect;
        // return mapping.findForward("ProductInfo");
    }

    //=================================================================
    public ActionForward SettingInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminFunctionality af = new AdminFunctionality();
        ((AdminBean) form).setSettings(af.getSetting());
        
        return mapping.findForward("SettingInfo");
    }
    
    public ActionForward updateSettings(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = ((AdminBean) form);
        Settings set = new Settings();
        set.setEmailId(bean.getEmailId());
        set.setRegisterationEmails(bean.getRegisterationEmails());
        set.setCareerEmails(bean.getCareerEmails());
        set.setSupplierEmails(bean.getSupplierEmails());
        set.setContactEmails(bean.getContactEmails());
        set.setUploadPath(bean.getUploadPath());
        set.setMaxPageRecords(bean.getMaxPageRecords());
        set.setEmailTime(bean.getEmailTime());
        set.setSmtpName(bean.getSmtpName());
        set.setSmtpUser(bean.getSmtpUser());
        set.setSmtpPassword(bean.getSmtpPassword());
        set.setProjectName(bean.getProjectName());
        set.setAdminMail(bean.getAdminMail());
        
        AdminFunctionality af = new AdminFunctionality();
        int x = af.updateSettings(set);
        System.out.println(x);
        ((AdminBean) form).setSettings(af.getSetting());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("SettingInfo"));
        return redirect;
        //return mapping.findForward("SettingInfo");
    }
    //=========================================================================

    public ActionForward UpdateAboutUs(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        CommonWSFunctionality f = new CommonWSFunctionality();
        Vector<AboutUs> aboutUsMenuAndContents = f.getAboutUsMenuAndContents();
        ((AdminBean) form).setAboutUs(aboutUsMenuAndContents);
        return mapping.findForward("UpdateAboutUs");
    }
    
    public ActionForward updateAboutUs(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        
        AdminFunctionality af = new AdminFunctionality();
        AdminBean bean = (AdminBean) form;
        
        System.out.println("id======" + bean.getAboutUsId());
        
        AboutUs a = new AboutUs();
        a.setAboutUsId(bean.getAboutUsId());
        a.setAboutUsTerm(bean.getAboutUsTerm());
        a.setAboutUsDescription(bean.getAboutUsDescription());
        // a.setAboutUsRank(bean.getAboutUsRank());
        a.setShowMenu(bean.getShowMenu());
        
        
        int updateAboutUs = af.updateAboutUs(a);
        System.out.println(updateAboutUs);
        CommonWSFunctionality f = new CommonWSFunctionality();
        Vector<AboutUs> aboutUsMenuAndContents = f.getAboutUsMenuAndContents();
        
        ((AdminBean) form).setAboutUs(aboutUsMenuAndContents);
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("UpdateAboutUs"));
        return redirect;
        //return mapping.findForward("UpdateAboutUs");
    }
    //===========================================================================

    public ActionForward SearchCVInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        UserFunctions uf = new UserFunctions();
        Vector<EducationLevels> eduLevels = uf.getEduLevels();
        Vector<StudyFields> studyFields = uf.getStudyFields();
        ((AdminBean) form).setLevels(eduLevels);
        ((AdminBean) form).setStudy(studyFields);
        ((AdminBean) form).setVac(uf.getVacncies());
        
        return mapping.findForward("SearchCVInfo");
    }
    
    public ActionForward searchByYOF(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        Vector<ApplicantCompanies> ac;
        Vector<ApplicantCompanies> ac2 = new Vector<ApplicantCompanies>();
        
        AdminBean bean = (AdminBean) form;
        Integer yearsOfExperince = bean.getYearsOfExperince();
        
        AdminFunctionality af = new AdminFunctionality();
        Vector<Applicants> searchByYOE = af.getSearchByYOE(yearsOfExperince);
        
        for (Iterator<Applicants> it = searchByYOE.iterator(); it.hasNext();) {
            Integer applicantId = it.next().getApplicantId();
            
            ac = af.getAppCompanies(applicantId);
            ac2.addAll(ac);
        }
        
        
        
        
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ((AdminBean) form).setCountries(uf.getCountries());
        ((AdminBean) form).setApplicants(searchByYOE);
        ((AdminBean) form).setApplicantCompanies(ac2);
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("SearchCVInfo"));
        return redirect;
        //return mapping.findForward("SearchCVInfo");
    }
    
    public ActionForward searchByEL(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminBean bean = (AdminBean) form;
        Integer el = bean.getEducationLevelId();
        AdminFunctionality af = new AdminFunctionality();
        Vector<Applicants> searchByEL = af.getSearchByEL(el);
        Vector<ApplicantCompanies> ac;
        Vector<ApplicantCompanies> ac2 = new Vector<ApplicantCompanies>();
        for (Iterator<Applicants> it = searchByEL.iterator(); it.hasNext();) {
            Integer applicantId = it.next().getApplicantId();
            ac = af.getAppCompanies(applicantId);
            ac2.addAll(ac);
        }
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ((AdminBean) form).setCountries(uf.getCountries());
        ((AdminBean) form).setApplicants(searchByEL);
        ((AdminBean) form).setApplicantCompanies(ac2);
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("SearchCVInfo"));
        return redirect;
        //return mapping.findForward("SearchCVInfo");
    }
    
    public ActionForward searchBySL(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminBean bean = (AdminBean) form;
        Integer el = bean.getStudyFieldId();
        AdminFunctionality af = new AdminFunctionality();
        Vector<Applicants> searchByEL = af.getSearchBySL(el);
        Vector<ApplicantCompanies> ac;
        Vector<ApplicantCompanies> ac2 = new Vector<ApplicantCompanies>();
        for (Iterator<Applicants> it = searchByEL.iterator(); it.hasNext();) {
            Integer applicantId = it.next().getApplicantId();
            ac = af.getAppCompanies(applicantId);
            ac2.addAll(ac);
        }
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ((AdminBean) form).setCountries(uf.getCountries());
        ((AdminBean) form).setApplicants(searchByEL);
        ((AdminBean) form).setApplicantCompanies(ac2);
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("SearchCVInfo"));
        return redirect;
        // return mapping.findForward("SearchCVInfo");
    }
    
    public ActionForward searchByGraduationYear(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminBean bean = (AdminBean) form;
        String el = bean.getGraduationYear();
        AdminFunctionality af = new AdminFunctionality();
        Vector<Applicants> searchByEL = af.getSearchByGY(el);
        Vector<ApplicantCompanies> ac;
        Vector<ApplicantCompanies> ac2 = new Vector<ApplicantCompanies>();
        for (Iterator<Applicants> it = searchByEL.iterator(); it.hasNext();) {
            Integer applicantId = it.next().getApplicantId();
            ac = af.getAppCompanies(applicantId);
            ac2.addAll(ac);
        }
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ((AdminBean) form).setCountries(uf.getCountries());
        ((AdminBean) form).setApplicants(searchByEL);
        ((AdminBean) form).setApplicantCompanies(ac2);
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("SearchCVInfo"));
        return redirect;
        // return mapping.findForward("SearchCVInfo");
    }
    
    public ActionForward searchByVacancy(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        AdminBean bean = (AdminBean) form;
        int el = bean.getVacancyId();
        AdminFunctionality af = new AdminFunctionality();
        Vector<Applicants> searchByEL = af.getSearchVacancies(el);
        Vector<ApplicantCompanies> ac;
        Vector<ApplicantCompanies> ac2 = new Vector<ApplicantCompanies>();
        for (Iterator<Applicants> it = searchByEL.iterator(); it.hasNext();) {
            Integer applicantId = it.next().getApplicantId();
            ac = af.getAppCompanies(applicantId);
            ac2.addAll(ac);
        }
        UserFunctions uf = new UserFunctions();
        ((AdminBean) form).setGrades(uf.getGrades());
        ((AdminBean) form).setCountries(uf.getCountries());
        ((AdminBean) form).setApplicants(searchByEL);
        ((AdminBean) form).setApplicantCompanies(ac2);
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("SearchCVInfo"));
        return redirect;
        // return mapping.findForward("SearchCVInfo");
    }

    //========================================================================
    public ActionForward ApplicantInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminFunctionality af = new AdminFunctionality();
        ((AdminBean) form).setApplicants(af.getApplicants());
        
        return mapping.findForward("ApplicantInfo");
    }
    
    public ActionForward deleteApplicant(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        int applicantId = ((AdminBean) form).getApplicantId();
        
        AdminFunctionality af = new AdminFunctionality();
        af.deleteApplicant(applicantId);
        ((AdminBean) form).setApplicants(af.getApplicants());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("ApplicantInfo"));
        return redirect;
        // return mapping.findForward("ApplicantInfo");
    }

    //========================================================================
    public ActionForward UserInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminFunctionality af = new AdminFunctionality();
        ((AdminBean) form).setUsers(af.getUsers());
        
        return mapping.findForward("UserInfo");
    }
    
    public ActionForward updateUser(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        
        
        AdminBean bean = (AdminBean) form;
        Users user = new Users();
        user.setUserId(bean.getUserId());
        user.setUserName(bean.getUserName());
        user.setUserEmail(bean.getUserEmail());
        user.setUserPassword(bean.getUserPassword());
        user.setUserType(bean.getUserType());
        System.out.println(bean.getQuestion());
        user.setQuestion(bean.getQuestion());
        user.setAnswer(bean.getAnswer());
        
        
        
        AdminFunctionality af = new AdminFunctionality();
        
        af.updateUser(user);
        
        ((AdminBean) form).setUsers(af.getUsers());
        
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("UserInfo"));
        return redirect;
    }
    
    public ActionForward deleteUser(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        long userId = ((AdminBean) form).getUserId();
        
        
        AdminFunctionality af = new AdminFunctionality();
        af.deleteUser(userId);
        ((AdminBean) form).setUsers(af.getUsers());
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("UserInfo"));
        return redirect;
        // return mapping.findForward("UserInfo");
    }
    //================================================

    public ActionForward UploadInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        return mapping.findForward("UploadInfo");
    }
    
    public ActionForward uploadInfo(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
        
        AdminBean bean = (AdminBean) form;
        FormFile uploadFile = bean.getUploadFile();
        String uploadFileName = bean.getUploadFileName();
        
        String type = uploadFile.getContentType();
        System.out.println(type);
        if (type.equalsIgnoreCase("image/png")
                || type.equalsIgnoreCase("image/jpeg")
                || type.equalsIgnoreCase("image/gif")
                || type.equalsIgnoreCase("image/bmp")
                || type.equalsIgnoreCase("image/ico")
                || type.equalsIgnoreCase("image/tiff")
                || type.equalsIgnoreCase("image/webp")) {
            ((AdminBean) form).setMsg("You are allowed to upload only Files, No images are allowed");
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("UploadInfo"));
            return redirect;
        }
        
        if (uploadFile.getFileName().length() == 0) {
            ((AdminBean) form).setMsg("File Can't be Empty, Please Pick a file to upload");
            ActionRedirect redirect =
                    new ActionRedirect(mapping.findForward("UploadInfo"));
            return redirect;
        }
        
        ServletContext servletContext = request.getServletContext();
        String path = "../../web/styles/upload/Files";
        
        String filePath = servletContext.getRealPath(path);
        
        
        
        
        String fileName2 = uploadFile.getFileName();
        
        if (!("").equals(fileName2)) {
            
            File newFile = new File(filePath, fileName2);
            
            Uploads upload = new Uploads();
            
            upload.setUploadTitle(uploadFileName);
            upload.setUploadUrl("styles/upload/Files/" + fileName2);
            AdminFunctionality af = new AdminFunctionality();
            int insertUpload = af.insertUpload(upload);
            if (insertUpload == 1) {
                ((AdminBean) form).setMsg("File Uploaded Successfuly");
            } else {
                ((AdminBean) form).setMsg("Problem Occurs, Can't Upload at a moment");
            }
            if (!newFile.exists()) {
                FileOutputStream fos = new FileOutputStream(newFile);
                fos.write(uploadFile.getFileData());
                fos.flush();
                fos.close();
                System.out.println("Uploaded");
            }
            
            
        }
        
        
        
        
        ActionRedirect redirect =
                new ActionRedirect(mapping.findForward("UploadInfo"));
        return redirect;
        
    }
}
